﻿using System.Linq;
using Complaint.Models.Dtos;

namespace Complaint.Repositories
{
    public class OrganisationAliasRepository : BaseRepository<OrganisationAlias>, IRepository<OrganisationAlias>
    {
        #region IRepository<OrganisationAlias> Members

        public void Create(OrganisationAlias dto)
        {
            ObjectContext.AddToOrganisationAlias(dto);
            Update(dto);
        }

        public IQueryable<OrganisationAlias> FindAll()
        {
            return ObjectContext.OrganisationAlias;
        }

        public OrganisationAlias FindById(int id)
        {
            return FindAll().FirstOrDefault(o => o.AliasID == id);
        }

        public IQueryable<OrganisationAlias> FindByName(string name)
        {
            return from orgAlias in FindAll()
                   where orgAlias.Alias == name
                   select orgAlias;
        }

        #endregion

        public IQueryable<OrganisationAlias> FindByOrganisation(int id)
        {
            return from orgAlias in FindAll()
                   where orgAlias.Organisation.OrganisationID == id
                   select orgAlias;
        }
    }
}